/**
* @description: 781. 森林中的兔子
* @author hewei
* @date 2022/8/23 15:36
* @version 1.0
*/

public class NumRabbits {

    public static void main(String[] args) {
        NumRabbits numRabbits = new NumRabbits();
        int[] nums = {1,0,1,0,0};
        System.out.println(numRabbits.numRabbits(nums));
    }

    public int numRabbits(int[] answers) {
        int[] nums = new int[1000];
        int ans = 0;
        for (int i : answers) {
            nums[i]++;
            if (nums[i] == 1) {
                ans += i + 1;
            }
            if (nums[i] == i + 1) nums[i] = 0;
        }
        return ans;
    }
}
